<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<!-- <div class="layui-card-header">客户管理</div> -->
						<div class="layui-card-body">
							<!-- 搜索 -->
							 <form class="layui-form search" id="form" onsubmit="return false" action="##">
							 	
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="会员编号" name="member_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">手机/名称：</label>
									<div class="layui-input-inline">
										<input class="layui-input" placeholder="手机/名称" name="keyword" autocomplete="off">
									</div>
								</div>
								
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form> 
							<!-- 搜索 -->
							
							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
							<script type="text/html" id="zizeng">
								{{d.LAY_TABLE_INDEX+1}}
							</script>
							
							<div class="layui-form-item layui-layout-admin">
								<div class="layui-input-block">
									<div class="layui-footer" style="left: 0;">
										<button class="layui-btn" id="queding">确定</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
					status:'1', 
				}
			function child(data,index){
				if(data.ascription){
					_data.ascription = data.ascription.split(",")
				}
				
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'form'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					admin = layui.admin;

			

				on_off_show("option")
				initdata();
				//监听搜索
				form.on('submit(search)', function(data) {
//					_data = data.field 
					Object.assign(_data, data.field)
					console.log(_data)
					initdata()
					return false;
				});
				function initdata() {
					table.render({
						elem: '#test-table-operate',
						url: server.member_query,
						height: 'full-105',
						cols: [
							[{type: 'checkbox', fixed: 'left'},
								 {
								field: 'memberid',
								width: 160,
								title: '会员ID',
							}, {
								field: 'name',
								width: 160,
								title: '会员姓名',
							}, {
								field: 'mobile',
								width: 160,
								title: '手机号码'
							},{							
								field: 'score', 
								title: '累计积分', 
								width: 120,
							},{
								field: 'grade', 
								title: '专属等级', 
								width: 120,
							},{
								field: 'truly_status',
								width: 100,
								title: '实名状态',
								templet: function(d) {
									return d.truly_status ? truly_status_show(1, d.truly_status) : ''
								}
							}, ]
						],
						page: true,
						where: _data,
						// limits: [3,5,10],
						limit: 20,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.shop_member.pager.total, //解析数据长度
								"data": res.shop_member.data //解析数据列表
							};
						},
						done: function(res, page, count){
//					        //可以自行添加判断的条件是否选中
//					        //这句才是真正选中，通过设置关键字LAY_CHECKED为true选中，这里只对第一行选中
//					        res.data[0]["LAY_CHECKED"]='true';
//					        //下面三句是通过更改css来实现选中的效果
//					        var index= res.data[0]['LAY_TABLE_INDEX'];
//					        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
//					        $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
					    }
					});
				}
				var _data = {};
				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					// console.log(obj)
					_data = obj.data
					console.log(_data)
				});
				$("button[type=reset]").on("click", function() {
						_data = {}
						initdata();
						document.getElementById("form").reset();
				});
				
				$('#queding').on('click',function(){
					
					var checkStatus = table.checkStatus('test-table-operate'),
							data = JSON.stringify(checkStatus.data);
					var id = "";
					for(var i = 0; i < checkStatus.data.length; i++) {
						id += checkStatus.data[i].memberid;
						if(i != checkStatus.data.length - 1) {
							id += ",";
						}
					} 
					_data.memberid = id
					console.log(_data)
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					if(JSON.stringify(_data) != '{}'){
						parent.$('input[name=member_id]').val("100000," + _data.memberid);
						//parent.$('input[name=name]').val(_data.name);  
						parent.layer.close(index); //再执行关闭
					} else {
						layer.msg('请选择一个')
					}
				});

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.test-table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

			});
		</script>
	</body>
</html>
